package com.example.service.impl;

import com.example.entity.FreeShop;
import com.example.mapper.FreeShopMapper;
import com.example.result.CommonResult;
import com.example.service.FreeShopService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.DecimalFormat;
import java.util.Date;
import java.util.Random;

/**
 * @author: tobed
 * @date: 2022/11/22
 * @time: 11:39
 */
@Service
public class FreeShopServiceImpl implements FreeShopService {

    @Autowired
    FreeShopMapper freeShopMapper;

    private static final Random random = new Random();
    private static final DecimalFormat sixdf = new DecimalFormat("000000");

    @Override
    public CommonResult createOder(FreeShop freeShop) {
        freeShop.setStatus(0);
        freeShop.setCreateTime(new Date());
        String format = sixdf.format(random.nextInt(1000000));
        freeShop.setFreeCode("ZH"+format+"WY");
        int i = freeShopMapper.insertSelective(freeShop);
        if (i!=0){
            return CommonResult.ok();
        }else{
            return CommonResult.fail(888,"网络异常");
        }
    }
}
